<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Request;

class UserAgent
{
    private static $guard = ["client", "php"];
    private static $userAgent = [];
    public static function toString(array $append = [])
    {
        self::defaultFields();
        $os = PHP_OS;
        $osVersion = php_uname("r");
        $osMode = php_uname("m");
        $userAgent = "AlibabaCloud (" . $os . " " . $osVersion . "; " . $osMode . ") ";
        $newUserAgent = [];
        $append = self::clean($append);
        $append = \AlibabaCloud\Client\Support\Arrays::merge([self::$userAgent, $append]);
        foreach ($append as $key => $value) {
            if($value === NULL) {
                $newUserAgent[] = $key;
            } else {
                $newUserAgent[] = $key . "/" . $value;
            }
        }
        return $userAgent . implode(" ", $newUserAgent);
    }
    private static function defaultFields()
    {
        if(self::$userAgent === []) {
            self::$userAgent = ["Client" => \AlibabaCloud\Client\AlibabaCloud::VERSION, "PHP" => PHP_VERSION];
        }
    }
    public static function clean(array $append)
    {
        foreach ($append as $key => $value) {
            if(self::isGuarded($key)) {
                unset($append[$key]);
            }
        }
        return $append;
    }
    public static function isGuarded($name)
    {
        return in_array(strtolower($name), self::$guard, true);
    }
    public static function append($name, $value)
    {
        \AlibabaCloud\Client\Filter\Filter::name($name);
        \AlibabaCloud\Client\Filter\Filter::value($value);
        self::defaultFields();
        if(!self::isGuarded($name)) {
            self::$userAgent[$name] = $value;
        }
    }
    public static function with(array $userAgent)
    {
        self::$userAgent = self::clean($userAgent);
    }
    public static function clear()
    {
        self::$userAgent = [];
    }
}

?>